<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

define( "JIEQI_MODULE_NAME", "system" );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( "system" );
jieqi_checkpower( $jieqiPower['system']['adminuser'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_loadlang( "users", JIEQI_MODULE_NAME );
jieqi_getconfigs( JIEQI_MODULE_NAME, "configs" );
include_once( JIEQI_ROOT_PATH."/admin/header.php" );
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) )
{
		$GLOBALS['_REQUEST']['page'] = 1;
}
include_once( JIEQI_ROOT_PATH."/class/users.php" );
$users_handler =& jieqiusershandler::getinstance( "JieqiUsersHandler" );
$criteria = new criteriacompo( );
switch ( $_REQUEST['sort'] )
{
case "experience" :
		$jieqiTpl->assign( "sort", "experience" );
		$jieqiTpl->assign( "usertitle", $jieqiLang['system']['top_user_experience'] );
		$criteria->setsort( "experience" );
		$criteria->setorder( "DESC" );
		break;
case "score" :
		$jieqiTpl->assign( "sort", "score" );
		$jieqiTpl->assign( "usertitle", $jieqiLang['system']['top_user_score'] );
		$criteria->setsort( "score" );
		$criteria->setorder( "DESC" );
		break;
case "monthscore" :
		$monthstart = mktime( 0, 0, 0, intval( date( "m", JIEQI_NOW_TIME ) ), 1, intval( date( "Y", JIEQI_NOW_TIME ) ) );
		$criteria->add( new criteria( "lastlogin", $monthstart, ">=" ) );
		$jieqiTpl->assign( "sort", "monthscore" );
		$jieqiTpl->assign( "usertitle", $jieqiLang['system']['top_user_monthscore'] );
		$criteria->setsort( "monthscore" );
		$criteria->setorder( "DESC" );
		break;
case "regdate" :
		$jieqiTpl->assign( "sort", "regdate" );
		$jieqiTpl->assign( "usertitle", $jieqiLang['system']['top_user_join'] );
		$criteria->setsort( "regdate" );
		$criteria->setorder( "DESC" );
}
$criteria->setlimit( $jieqiConfigs['system']['topuserpnum'] );
$criteria->setstart( ( $_REQUEST['page'] - 1 ) * $jieqiConfigs['system']['topuserpnum'] );
$users_handler->queryobjects( $criteria );
$userrows = array( );
$k = 0;
while ( $v = $users_handler->getobject( ) )
{
		$userrows[$k]['uid'] = $v->getvar( "uid" );
		$userrows[$k]['uname'] = $v->getvar( "uname" );
		$userrows[$k]['regdate'] = date( JIEQI_DATE_FORMAT, $v->getvar( "regdate" ) );
		$userrows[$k]['group'] = $v->getgroup( );
		$userrows[$k]['sex'] = $v->getsex( );
		$userrows[$k]['email'] = $v->getvar( "email" );
		$userrows[$k]['url'] = $v->getvar( "url" );
		$userrows[$k]['qq'] = $v->getvar( "qq" );
		$userrows[$k]['msn'] = $v->getvar( "msn" );
		$userrows[$k]['experience'] = $v->getvar( "experience" );
		$userrows[$k]['monthscore'] = $v->getvar( "monthscore" );
		$userrows[$k]['score'] = $v->getvar( "score" );
		$userrows[$k]['egold'] = $v->getvar( "egold" );
		$userrows[$k]['esilver'] = $v->getvar( "esilver" );
		$userrows[$k]['emoney'] = $userrows[$k]['egold'] + $userrows[$k]['esilver'];
		$userrows[$k]['lastlogin'] = date( JIEQI_DATE_FORMAT, $v->getvar( "lastlogin" ) );
		++$k;
}
$jieqiTpl->assign_by_ref( "userrows", $userrows );
include_once( JIEQI_ROOT_PATH."/lib/html/page.php" );
$jumppage = new jieqipage( $users_handler->getcount( $criteria ), $jieqiConfigs['system']['topuserpnum'], $_REQUEST['page'] );
$jieqiTpl->assign( "url_jumppage", $jumppage->whole_bar( ) );
$jieqiTpl->setcaching( 0 );
$jieqiTset['jieqi_contents_template'] = JIEQI_ROOT_PATH."/templates/admin/topuser.html";
include_once( JIEQI_ROOT_PATH."/admin/footer.php" );
?>
